{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from src import Preproduction as Pre\n",
    "\n",
    "id, ch = Pre.load(\"results/hanzi_2_one_hot.data\")\n",
    "cnt = len(ch)\n",
    "V = 10000\n",
    "\n",
    "print(\"cnt = \" + str(cnt))\n",
    "print(\"V = \" + str(V))\n",
    "\n",
    "from src.EmbeddingGloVe import genX as genX\n",
    "from src.EmbeddingGloVe import Glove as Glove\n",
    "\n",
    "pathBase = 'dataset/chat_corpus/clean_chat_corpus/'\n",
    "paths = [\n",
    "    \"chatterbot.tsv\",\n",
    "    \"douban_single_turn.tsv\",\n",
    "    \"ptt.tsv\",\n",
    "    \"qingyun.tsv\",\n",
    "    \"subtitle.tsv\",\n",
    "    \"tieba.tsv\",\n",
    "    \"weibo.tsv\"\n",
    "]\n",
    "fullPaths = [pathBase + path for path in paths]\n",
    "\n",
    "import numpy as np\n",
    "import random\n",
    "\n",
    "from src.GeneratorLSTMv9 import LSTM\n",
    "\n",
    "embDim = 128\n",
    "hidDim = 512\n",
    "seqLen = 30\n",
    "\n",
    "lstm = LSTM(embDim, hidDim, V)\n",
    "lstm.load(\"results/V9LSTM050.model\")\n",
    "\n",
    "def Gen(cur):\n",
    "    x = [id[i] if id[i] < V else 0 for i in cur]\n",
    "    e = lstm.eval(x)\n",
    "    res = ''\n",
    "    for i in e:\n",
    "        res += ch[i] if i > 1 else ''\n",
    "    return res\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def handle(conf):\n",
    "    \"\"\"\n",
    "    该方法是部署之后，其他人调用你的服务时候的处理方法。\n",
    "    请按规范填写参数结构，这样我们就能替你自动生成配置文件，方便其他人的调用。\n",
    "    范例：\n",
    "    params['key'] = value # value_type: str # description: some description\n",
    "    value_type 可以选择：img, video, audio, str, int, float, [int], [str], [float]\n",
    "    参数请放到params字典中，我们会自动解析该变量。\n",
    "    \"\"\"\n",
    "\n",
    "    cur = conf['request']  # value_type: str # description: The sentence to speak to the model\n",
    "    \n",
    "    # add your code\n",
    "    return {'response': Gen(cur)}\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
